package cn.py.boot_lua.processTa;

import cn.py.boot_lua.handler.generic.QueueType;
import cn.py.boot_lua.processTa.impl.BackTaskStrategy;
import cn.py.boot_lua.processTa.impl.CaptionTaskStrategy;
import cn.py.boot_lua.processTa.impl.StoryTaskStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

// 策略工厂
@Slf4j
@Component
public class StrategyFactory {

    private final Map<QueueType, TaskProcessStrategy> strategyMap = new ConcurrentHashMap<>();
    public StrategyFactory(List<TaskProcessStrategy> strategies) {
        for (TaskProcessStrategy strategy : strategies) {
            Strategy annotation = strategy.getClass().getAnnotation(Strategy.class);
            if (annotation != null) {
                strategyMap.put(annotation.value(), strategy);
            }
        }
    }

    public TaskProcessStrategy getStrategy(QueueType type) {
       return strategyMap.get(type);
    }

}
